<!doctype html>
<html lang="en">
<head>
    @include('web.layout.head')
    <link rel="stylesheet" href="{{mix('/css/web/user/prove_release.css')}}">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    @include('UEditor::head')
</head>
<body>
@include('web.layout.header')
@include('web.layout.user_tab')
<div class="base_member_content">
    <div class="w1200">

        @include('web.layout.seller_nav')
        <div class="nav_right flr">
            <form action="{{$request_url}}" method="post" id="frm-post">
              @if(isset($type) && $type == 'put')
                                {{method_field("PUT")}}
                            @endif
            <input type="hidden" name="first_cat" value="{{old('first_cat')}}" />
            <input type="hidden" name="second_cat" value="{{old('second_cat')}}" />
            <input type="hidden" name="third_cat" value="{{old('third_cat')}}" />

		<input type="hidden" name="cate_type" value="{{old('cate_type')}}" />

            <div class="marryreal">
                <div class="name"><span class="goodsfabu">产品详情</span>
                    <div class="steps">
                        <span class="xuanz">1.选择类目</span>
                        <span class="xuanz">2.填写商品详情</span>
                        <span class="xuanzno">3.提交成功</span>
                    </div>
                </div>
                <div class="clear"></div>
                 <div class="nowxz">
                    <span>您当前选中的类目：</span>
                    <span>{{old('c1')}}</span>
                    &gt;<span>{{old('c2')}}</span>
                    &gt;<span>{{old('c3')}}</span>
                     @if(old('id'))
                    <span class="reset"><a href="/member/seller/product/create?step=cate&id={{old('id')}}" rel="nofollow">(返回重选类目)</a></span>
                    @else
                     <span class="reset"><a href="/member/seller/product/create?step=cate" rel="nofollow">(返回重选类目)</a></span>
                    @endif
                </div>
                <div class="name">基本信息</div>
                <div class="content" style="min-height: auto">

                      <div class="hang">
                        <div class="name"><span class="red">*</span>资质名称</div>
                        <div class="nameright">
			 <input value="-" type="hidden" name="product_desc" />
                            <input value="{{old('name')}}" type="text" name="name" class="goodstitle" onkeyup="words_deal(this, 50);" placeholder="请填写品牌、产品名称、产品型号、产品特征及具体描述"> <span class="textCount">0</span><span>/50</span><span class="maxtitle">超过最大可输入字数</span>
                            @if($errors->has('name'))
<div class="jm_error" id="cptitle">资质名称必填</div>
@endif
                        </div>
                    </div>


  					 @if(is_array(old('attrs')))
                        @foreach(old('attrs') as $attr)
                        <div class="hang">
               <div class="name"><span class="red">*</span>{{$attr['name']}}</div>
                         <div class="nameright">
                         <div class="namedt">
                              <?php
                            $exit_sku = true;
                            $attr_ids = json_decode(old('attr_ids'),true);
                            $not_select = "";
                            if(!$attr_ids){
                                $attr_ids = [];
                            }else{
                                $not_select = "disabled='disabled'";
                            }
                            ?>
                            @if(isset($attr['values']) && $attr['values'] )
                            <select class="product_attrs" name="product_attrs[]"    >
                            @foreach($attr['values'] as $k=>$val)
                                <option   class="sku_value" propvalid='{{$k}}'  propid='{{$attr['attribute_id']}}' value="{{$attr['attribute_id']}}:{{$attr['name']}},{{$k}}:{{$val}}"  <?php   if(in_array($attr['attribute_id'].':'.$attr['name'].','.$k.':'.$val, $attr_ids)){?>  selected="selected"  <?php }?> >{{$val}}</option>
                            @endforeach
                            </select>
                            @endif
                            </div>
                   </div>
                         </div>
                           @endforeach
                           @endif


                    <div class="hang top">
                        <div class="name"><span class="red">*</span>盖章费(元)</div>
                        <div class="nameright2">
                            <div class="namedt" style="position: relative;">
                                <input value="{{old('price')}}" type="text" name="price" class="minorder price" id="attr_price"  onkeyup="onlyNumber(this)" onblur="onlyNumber(this)"  autocomplete="off" data-region-id="">
                            </div>
                             @if($errors->has('price'))
                            <div class="jm_error fl" id="err_placeOrigin">盖章费(元)必填</div>
                            @endif
                        </div>
                    </div>


                      <div class="hang top">
                        <div class="name"><span class="red">*</span>地址</div>
                        <div class="nameright2">
                            <div class="namedt" style="position: relative;">
                                <input value="{{old('place_origin')}}" type="text" name="place_origin" class="minorder placeOrigin" id="selected_city"  autocomplete="off" data-region-id="">
                                @include('web.layout.city_placeOrigint')
                            </div>
                             @if($errors->has('place_origin'))
                            <div class="jm_error fl" id="err_placeOrigin">产地必填</div>
                            @endif
                        </div>
                    </div>
                <div class="content" style="min-height: auto">
                    <div class="hang">
                        <div class="name namefilee" ><span class="red">*</span>列表图</div>
                        <div class="nameright">
                            <div class="modify fl fontsize" >
                                <div class="imgbox">
                                    <div class="list_image fl">
                                    <?php if(old('cover_image')){?>
                                        <div class="upload-img-item">
                                            <img src="/img/web/user/close.png" class="icon-colse" >
                                            <img src="{{old('cover_image')}}"  class="shangchuan btn_listimg" data-id="0"
                                            style="cursor: pointer">
                                        </div>
                                        <input type="hidden" name="cover_image" value="{{old('cover_image')}}">
                                    <?php } else {?>
                                        <div class="upload-img-item">
                                            <img src="{{asset('/img/web/user/fileOne.png')}}"  class="shangchuan btn_listimg" data-id="0" title="点此上传商品图片" style="cursor: pointer">
                                        </div>
                                        <input type="hidden" name="cover_image">
                                        <?php } ?>
                                        <img src="{{asset('/img/web/user/fileOne.png')}}" style="display: none" class="default_img" />
                                    </div>
                                </div>
                            </div>
                        </div>
                        @if($errors->has('cover_image'))
                        <div class="jm_error fl" id="err_listimg">请上传列表图</div>
                        @endif
                    </div>
                    <div class="hang top">
                        <div class="name namefilee" ><span class="red">*</span>主图(详情页)</div>
                        <div class="nameright">
                            <div class="modify fl fontsize" >
                                <div class="imgbox">


                                		    <?php

    		    if(!is_array(old('images'))){
    		        $images = json_decode(old('images'),true);
    		    }else{
    		        $images = old('images');
    		    }

    		    if(!is_array($images)){
                    $images = old('images');
                    if($images){
                     echo '<div class="upload-img-item"><img src="/img/web/user/close.png" class="icon-colse" >
                                			<img src="'.$images.'"  class="shangchuan">
                                		</div>';
                    }
                }else{
                    foreach($images as $img){
                        echo '<div class="upload-img-item"><img src="/img/web/user/close.png" class="icon-colse" >
                                			<img src="'.$img.'"  class="shangchuan">
                                		</div>';
                    }
                }
                ?>


                                    <img src="{{asset('/img/web/user/file.png')}}"    title="点此上传商品图片" class="shangchuan btn_detailimg" style="cursor: pointer; " id="upload-img" data-id="1"/>
                                </div>
                            </div>
                        </div>
                        @if($errors->has('images'))
                        <div class="jm_error fl" id="err_image">请上传主图</div>
                        @endif
                    </div>
                    <div class="hang top">
                        <div class="name"><span class="red">*</span>商品详情</div>
                        <div class="nameright">
                            <script id="editor_id" name="product_detail"  style="min-height:300px;" type="text/plain"> {!! old('product_detail') !!} </script>
                             @if($errors->has('product_detail'))
                            <div class="jm_error fl" id="err_content">商品详情必填</div>
                            @endif
                        </div>
                    </div>

                    <div class="hang top">
                        <div class="name">橱窗推荐</div>
                        <div class="nameright">
                            <div class="namedt windowlist">
                                <label><input class="window" type="checkbox" name="is_cupboard"  @if(old('is_cupboard') == 1) checked="checked"   @endif  value="1" />是</label>
                                <span>您的橱窗使用情况：共<font>【15】</font>个，已用【{{old('cupboards')}}】个。</span>
                            </div>
                        </div>
                    </div>
                </div>
                {{csrf_field()}}
                <input type="hidden" id="after_sale_guarantee" name="after_sale_guarantee" value="">
                <input type="hidden" id="is_for_sale" name="is_for_sale" value="0">
                <?php
                if(!is_array(old('images'))){
                    $images = json_decode(old('images'),true);
                }else{
                    $images = old('images');
                }


                if(!is_array($images)){
                    $images = old('images');
                    if($images){
                        echo '<input type="hidden" name="images[]" value="'.$images.'" class="j-hid-images">';
                    }
                }else{
                    foreach($images as $img){
                        echo '<input type="hidden" name="images[]" value="'.$img.'" class="j-hid-images">';
                    }
                }
                ?>
                <input type="submit" data-type="0" class="drafts" value="保存至草稿箱">
                <input type="submit" data-type="1" class="tijiao" value="发布产品">
            </div>
            </form>
        </div>
    </div>
</div>
<form id="uploadForm" action="{{url('uploads/images')}}" method="post">
    {{csrf_field()}}
    <input style="display: none;" name="image" type="file" class="inputFile" />
</form>
@include('web.layout.footer')
<script src="{{mix('/js/web/image/uploadPreview.min.js')}}"></script>
<script src="{{mix('/js/web/user/jquery.charfirst.pinyin.js')}}"></script>
<script src="{{mix('/js/web/user/sort.js')}}"></script>
<script src="{{mix('/js/web/inc/fileUpload.js')}}"></script>
<script type="text/javascript">
function onlyNumber(obj) {
    //得到第一个字符是否为负号
    var t = obj.value.charAt(0);
    //先把非数字的都替换掉，除了数字和.
    obj.value = obj.value.replace(/[^\d\.]/g, '');
    //必须保证第一个为数字而不是.
    obj.value = obj.value.replace(/^\./g, '');
    //保证只有出现一个.而没有多个.
    obj.value = obj.value.replace(/\.{2,}/g, '.');
    //保证.只出现一次，而不能出现两次以上
    obj.value = obj.value.replace('.', '$#$').replace(/\./g, '').replace(
            '$#$', '.');
    //如果第一位是负号，则允许添加
    if (t == '-') {
        obj.value = '-' + obj.value;
    }
}

    // 增加商品属性的js
    $(function () {
        // Stuff to do as soon as the DOM is ready;
        $(document).on("click", ".addrow", function () {
            var addcolumn = "<div class='rowh'><div class='row_name'><input type='text' name='' placeholder='请输入属性名'></div><div class='row_right'><input type='text' name='' placeholder='请输入属性值'></div></div>";
            $(".isjiaruh").append(addcolumn);
            $(".rowh").each(function () {
                if ($(".rowh").length > 10) {
                    $(".addrow").attr("disabled", true);
                    return false;
                }
            });
        });


        $(".num_name").click(function () {
            var $this = $(this);
            $(".qxzbrands")[0].innerText = $this.text();
            $('#brands').find('input[name="brand_id"]').val($this.data('id'));
            $(".brandsxuanze").hide();
        });

        $(".service").click(function(){
        	 var service ='';
        	    $(".service").each(function(){
        	        if($(this).is(':checked')){
        	            service= service +$(this).val() + ',';
        	        }
        	    });
        	    service = service.substring(0,service.length -1);
        	    $('#after_sale_guarantee').val(service);
         });
		$(".window").click(function(){
			if($(this).is(':checked')){
				$(this).val(1);
			}else{
				$(this).val(0);
			}

		});

        $(".tijiao, .drafts").click(function () {
        	 $('#is_for_sale').val($(this).data('type'));


        	// getAlreadySetSkuVals();
        	// var sku_input_num = 0;
         //    $('.skuTable input[type="text"]').each(function(){
         //        if($(this).val() == ''){
         //            sku_input_num++;
         //        }
         //    })
         //    if (sku_input_num > 0 || $('.skuTable input[type="text"]').length  == 0){
         //        $("#err_sku").html('请填写商品规格');
         //        return false;
         //    } else {
         //        $("#err_sku").html('');
         //    }


        });
        var formtype = '{{isset($type)?$type:'POST'}}';
        if (formtype=='put') {
            $("#frm-post").on('submit', function (e) {
                e.preventDefault();
                form = $('#frm-post');
                data = form.serialize();
                url = form.attr('action');
                $.ajax({
                    url: url,
                    type: formtype,
                    data: data,
                    success: function (res) {
                        console.log(res);
                        if (res.code == 0) {
                            layer.confirm('保存成功！', {
                                btn: ['确定', '取消'] //可以无限个按钮
                            }, function () {
                                location.href = '/member/seller/product?product_type=2&@if(session('current_page'))page={{session('current_page')}}@endif';
                            }, function (index) {
                                layer.close(index);
                            });
                        } else {
                            layer.alert(res.message, {
                                title: '提示',
                                icon: 2
                            });
                        }
                    },
                    error: function () {
                    }
                });
            });
        }
            var img_type;
        // 图片上传点击
        $('.btn_listimg, .btn_detailimg').click(function () {
            img_type = $(this).attr('data-id');
            if(img_type == 1){
                var _length = $(this).parent().find('.shangchuan').length
                if (_length < 6) {
                    $('.inputFile').trigger('click');
                } else {
                    layer.alert('最多可上传五张商品图', {
                        title:'提示',
                        icon: 2
                    });
                }
            }else{
                $('.inputFile').trigger('click');
            }
        });
        $(document).on('mouseover', '.upload-img-item', function () {
            var $this = $(this);
            $this.find('.icon-colse').show();
        }).on('mouseout', '.upload-img-item', function () {
            var $this = $(this);
            $this.find('.icon-colse').hide();
        });
        $(document).on('click', '.icon-colse', function () {
            var $this = $(this), img_name = $this.parent().find('.shangchuan').attr('src');
            $("#frm-post").find('input[class="j-hid-images"]').each(function () {
                if (img_name == $(this).val()){
                    $(this).remove();
                }
            });

            if($this.parent().parent().hasClass("list_image")){
                $(".list_image input[name=cover_image]").val('')
                $this.siblings(".btn_listimg").attr("src",$('.default_img').attr("src"))
                $this.remove()
            }else{
                $this.parent().remove();
            }
        });
        // 选择完要上传的文件后, 直接触发表单提交
        $('input[name=image]').on('change', function () {
            if ($.trim($(this).val())) {
                $("#uploadForm").trigger('submit');
            }
             //防止选择同个文件上传不触发该事件
            $(this).val('')
        });

        // 图片上传
        $("#uploadForm").on('submit', function (e) {
            e.preventDefault();
            // $.ajax({
            //     url: "{{url('uploads/images')}}",
            //     type: "POST",
            //     data: new FormData(this),
            //     contentType: false,
            //     cache: false,
            //     processData: false,
            //     // 显示加载图片
            //     success: function (res) {
            //         if (res.status == 0){
            //             var img_path = '' + res.path;
            //             if(img_type == 0){
            //                 var html = '<div class="upload-img-item"><img src="'+ img_path +'" class="shangchuan" /></div><input type="hidden" name="cover_image" value="'+ img_path +'"/>';
            //                 $(".list_image").html(html);
            //             }else{
            //                 $("#upload-img").parent().prepend('<div class="upload-img-item"><img src="/img/web/user/close.png" class="icon-colse" /><img src="'+ img_path +'" class="shangchuan" /></div>');
            //                 $("#frm-post").append('<input type="hidden" name="images[]" value="'+ img_path +'" class="j-hid-images"/>');
            //             }
            //             layer.alert('图片上传成功', {
            //                 title:'提示',
            //                 icon: 1
            //             });
            //         } else {
            //             layer.alert('图片上传失败', {
            //                 title:'提示',
            //                 icon: 2
            //             });
            //         }
            //     },
            //     error: function () { }
            // });
            var cb=function(res){
                var img_path = '' + res.path;
                if(img_type == 0){
                    $(".list_image .shangchuan").attr("src",img_path)
                    $(".list_image input[name=cover_image]").val(img_path)
                    var ele=$(".list_image .upload-img-item")
                    if(ele.find('.icon-colse').length==0){
                        ele.prepend('<img src="/img/web/user/close.png" class="icon-colse" >')
                    }
                }else{
                    $("#upload-img").parent().append('<div class="upload-img-item"><img src="/img/web/user/close.png" class="icon-colse" /><img src="'+ img_path +'" class="shangchuan" /></div>');
                    $("#frm-post").append('<input type="hidden" name="images[]" value="'+ img_path +'" class="j-hid-images"/>');
                }
            }
            uploadFile("{{url('uploads/images')}}",new FormData(this),cb)
        });

    });

    // 限制输入长度
    function words_deal(obj, len) {
        var $this = $(obj);
        var curLength = $this.val().length;
        if (curLength > len) {
            var num = $this.val().substr(0, len);
            $this.val(num);
            $this.parent().find(".maxtitle").show();
        } else {
            $this.parent().find(".textCount").text(len - $this.val().length);
            $this.parent().find(".maxtitle").hide();
        }
    }

    var ue_detail = UE.getEditor('editor_id', { initialFrameWidth: null });
    ue_detail.ready(function() {
        ue_detail.execCommand('serverparam', '_token', '{{ csrf_token() }}'); // 设置 CSRF token.
    });

$(function(){


});

</script>
</body>


</html>
